package mm.chenchen.modules.sys.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import mm.chenchen.modules.sys.entity.FastStartDataSource;
import mm.chenchen.modules.sys.service.FastStartDataSourceService;
import mm.chenchen.modules.sys.dao.model.request.FastStartDataSourceQuery;
import mm.chenchen.utils.PageUtils;
import mm.chenchen.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;

/**
 * @author
 * @email
 * @date 2021-07-02 16:49:50
 */
@RestController
@Api(tags = "数据源管理")
@RequestMapping("sys/faststartdatasource")
@CrossOrigin
public class FastStartDataSourceController extends AbstractController{
    @Autowired
    private FastStartDataSourceService service;

    @PostConstruct
    public void initDS() {
        service.initDataSource();
    }

    /**
     * 列表
     */
    @ApiOperation(value = "分页检索", notes = "")
    @PostMapping("/list")
    //@RequiresPermissions("sys:faststartdatasource:list")
    public R findPage(@RequestBody FastStartDataSourceQuery param) {
        return service.findPage(PageUtils.getPage(param), param);
    }


    /**
     * 信息
     */
    @ApiOperation(value = "单个检索 ", notes = "")
    @GetMapping(value = "/{objId}", produces = "application/json")
    //@RequiresPermissions("sys:faststartdatasource:info")
    public R getById(@ApiParam(name = "objId", value = "") @PathVariable Integer objId) {
        return service.getById(objId);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增", notes = "")
    @PostMapping(value = "", produces = "application/json")
    //@RequiresPermissions("sys:faststartdatasource:save")
    public R save(@RequestBody FastStartDataSource param) {
        return service.saveInfo(param);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新", notes = "")
    @PutMapping(value = "/{objId}", produces = "application/json")
    //@RequiresPermissions("sys:faststartdatasource:update")
    public R update(@ApiParam(name = "objId", value = "") @PathVariable Integer objId, @RequestBody FastStartDataSource param) {
        param.setId(objId);
        return service.update(param);
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除", notes = "")
    @DeleteMapping(value = "/{objId}", produces = "application/json")
    //@RequiresPermissions("sys:faststartdatasource:delete")
    public R deleteById(@ApiParam(name = "objId", value = "") @PathVariable Integer objId) {
        return service.deleteById(objId);
    }

}
